
import store from '../store'
import Cookies from 'js-cookie'
// console.log(123123)
// console.log(store.state.openid)
// console.log(123123)
let fun = (title, desc, urls, image, other) => {
  console.log(urls)
  return new Promise((resolve, reject) => {
    let links
    if (other) {
      links = window.location.origin.split('#')[0] + `?shareDefault=fenxiang&shareid=${store.state.openid}&url=${urls}` + `${other}`
    } else {
      links = window.location.origin.split('#')[0] + `?shareDefault=fenxiang&shareid=${store.state.openid}&url=${urls}`
    }
    console.log(links)
    wx.ready(() => {
      var shareData = {
        title: title,
        desc: desc,
        link: links,
        imgUrl: image || 'https://o6wndwjxn.qnssl.com/logo.png', // 分享图片
        success: function (res) {
          Cookies.set('theRequest', '')
          resolve(res)
          // console.log(`分享成功`)
        },
        cancel: function (res) {
          // console.log(`取消分享`)
          resolve(res)
        }
      }
      wx.onMenuShareAppMessage(shareData)
      wx.onMenuShareTimeline(shareData)
    })
  })
}

export default fun
